import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class demo7 {
    public static void main(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "张无忌-男-15", "周芷若-女-14", "赵敏-女-13",
                "张强-男-20", "张三丰-男-100", "张翠山-男-40", "张良-男-35", "王二麻子-男-37", "谢广坤-男-41");

        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2, "张无忌-男-15","张无忌-男-15", "周芷若-女-14", "赵敏-女-13",
                "张强-男-20", "张三丰-男-100", "张翠山-男-40", "张良-男-35", "王二麻子-男-37", "谢广坤-男-41");

        //目标提取男性的年龄
        List<String> collect = list1.stream().filter(x -> "男".equals(x.split("-")[1]))
                .collect(Collectors.toList());
        System.out.println(collect);

        //转化为set可以去重
        Set<String> collect1 = list2.stream().filter(x -> "男".equals(x.split("-")[1]))
                .collect(Collectors.toSet());

        System.out.println(collect1);

        //转化为map
        Map<String, Integer> collect2 = list1.stream().filter(x -> "男".equals(x.split("-")[1]))
                .collect(Collectors.toMap(
                        new Function<String, String>() {
                            @Override
                            public String apply(String s) {
                                return s.split("-")[0];
                            }
                        },
                        new Function<String, Integer>() {

                            @Override
                            public Integer apply(String s) {
                                return Integer.parseInt(s.split("-")[2]);
                            }
                        }
                ));

        Map<String, Integer> collect3 = list1.stream().filter(x -> "男".equals(x.split("-")[1]))
                .collect(Collectors.toMap(s -> s.split("-")[0],
                        s -> Integer.parseInt(s.split("-")[2])));

        System.out.println(collect2);
        System.out.println(collect3);


    }
}
